import * as API from '@/services';
import {
  KfBackendEnumPicker,
  DEFAULT_FORM_LAYOUT,
  KfBizQuickFormProps,
  KfFloatingContextProps,
  KfInput,
  KfQuickForm,
  KfTextArea,
  KfDatePicker,
  KfDateStringPicker,
} from 'kf-web-library';
import {Col, Form, Row} from 'antd';
import React, {FunctionComponent} from 'react';

const FormItem = Form.Item;
type QueryEntity = API.ManuscriptInvitation;
type CreateEntity = API.ManuscriptInvitation_Create;
type ModifyEntity = API.ManuscriptInvitation_Modify;

type DataFormProps = {} & KfBizQuickFormProps & KfFloatingContextProps;

/**
 * 约稿管理 表单
 */
const QuickForm: FunctionComponent<DataFormProps> = (props) => {
  const {formType, bizId, ...rest} = props;

  return (
    <KfQuickForm
      formType={formType}
      formProps={{
        labelCol: {
          flex: '0 0 100px',
        },
        wrapperCol: {
          flex: '1',
        },
      }}
      defaultQueryRequest={() =>
        API.queryManuscriptInvitation(bizId!).then((resp) => {
          if (resp.flag) {
            resp.data = {
              ...resp.data,
            };
          }
          return new Promise((resolve) => resolve(resp));
        })
      }
      submitRequest={{
        create: (formValues) => API.createManuscriptInvitation({...formValues} as CreateEntity),
        modify: (formValues) => API.modifyManuscriptInvitation({...formValues, id: bizId} as ModifyEntity),
      }}
      {...rest}
    >
      <Row>
        <Col span={24}>
          <FormItem name={nameof<ModifyEntity>((x) => x.authorName)} label="邀约人姓名" rules={[{required: true}]}>
            <KfInput/>
          </FormItem>
        </Col>
        <Col span={12}>
          <FormItem name={nameof<ModifyEntity>((x) => x.authorEmail)} label="联系邮箱" rules={[{required: false}]}>
            <KfInput/>
          </FormItem>
        </Col>
        <Col span={12}>
          <FormItem name={nameof<ModifyEntity>((x) => x.authorPhone)} label="联系电话" rules={[{required: false}]}>
            <KfInput/>
          </FormItem>
        </Col>
        <Col span={24}>
          <FormItem name={nameof<ModifyEntity>((x) => x.topic)} label="约稿主题" rules={[{required: true}]}>
            <KfInput/>
          </FormItem>
        </Col>
        <Col span={12}>
          <FormItem name={nameof<ModifyEntity>((x) => x.columnName)} label="约稿栏目" rules={[{required: false}]}>
            <KfInput/>
          </FormItem>
        </Col>
        <Col span={24}>
          <FormItem name={nameof<ModifyEntity>((x) => x.status)} label="约稿状态" rules={[{required: true}]}>
            <KfBackendEnumPicker.Select enumType="InvitationStatus"/>
          </FormItem>
        </Col>
        <Col span={24}>
          <FormItem name={nameof<ModifyEntity>((x) => x.articleDate)} label="发文时间" rules={[{required: false}]}>
            <KfDateStringPicker/>
          </FormItem>
        </Col>
        <Col span={24}>
          <FormItem name={nameof<ModifyEntity>((x) => x.articleLink)} label="发文链接" rules={[{required: false}]}>
            <KfInput placeholder="https://xxx.com"/>
          </FormItem>
        </Col>
      </Row>



    </KfQuickForm>
  );
};

export default QuickForm;
